package com.peng.leetcode.other;

import java.util.HashSet;
import java.util.Set;

/**
 * LengthOfLongestSubstring
 *
 * @author: lupeng6
 * @create: 2020/10/9 16:43
 */
public class LengthOfLongestSubstring {

    public static void main(String[] args) {
        String str = "";
        System.out.println(new Solution().lengthOfLongestSubstring(str));
    }


    static class Solution {
        public int lengthOfLongestSubstring(String s) {
            if (s == null || s.length() == 0) {
                return 0;
            }
            Set<Character> hashSet = new HashSet<Character>();
            int maxLength = 0;
            for (int i = 0; i < s.length(); i++) {
                int currentLength = 0;
                for (int j = i; j < s.length(); j++) {
                    Character character = new Character(s.charAt(j));
                    if (hashSet.contains(character)) {
                        hashSet = new HashSet<Character>();
                        maxLength = maxLength < currentLength ? currentLength : maxLength;
                        break;
                    } else {
                        hashSet.add(character);
                        currentLength ++;
                    }
                    maxLength = maxLength < currentLength ? currentLength : maxLength;
                }
            }
            return maxLength;
        }
    }

}
